(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";

loader.define({
  depend: ['pages/config/config'],
  loaded: function loaded(config, require, exports, module, global) {
    this.pageview = {
      init: function init(e) {
        var i;
        var loadcheck = ""; //回退界面

        $("#back_btn").click(function () {
          bui.back();
          bui.ajax({
            url: config.apiurl + "api/v1.0/mychange",
            data: {},
            method: "post",
            headers: {
              'Content-Type': 'application/json'
            }
          }).done(function (res) {
            $("#p3").text(res['acts']);
          });
        }); // //点赞事件处理
        // $(".thrumbs").click(function(){
        //     if($(".thrumbs").attr("src").match("images/home/thrumbs-down.png"))
        //         $(this).attr("src","images/home/thrumbs-up.png");
        //     else
        //         $(this).attr("src","images/home/thrumbs-down.png");
        // });
        //滑动页面布局加载

        var uiList = bui.list({
          id: "#scrollList",
          url: config.apiurl + "api/v1.0/myact",
          pageSize: 1000000,
          // 当pageSize 小于返回的数据大小的时候,则认为是最后一页,接口返回的数据最好能返回空数组,而不是null
          data: {},
          //如果分页的字段名不一样,通过field重新定义
          field: {
            page: "page",
            size: "pageSize",
            data: "activities"
          },
          callback: function callback(e) {//console.log("1:   "+e);
            // e.target 为你当前点击的元素
            // e.currentTarget 为你当前点击的handle 整行
          },
          template: function template(data) {
            var html = "";
            data.forEach(function (el, index) {
              console.log(el); //var type,lng,lat;

              var i = index % 4;
              var panel= `<li class="bui-btn bui-box" id="listcontainer" style="background:url(images/home/panel_${i}.png) no-repeat;background-size: 100% 100%;">
                                        <div id="panelcontainer">
                                            <div id="activityname">
                                                <h1 class="nop">${el.name}</h1>
                                            </div>
                                            <div class="bui-box buttonlist" >
                                            <button class = "btn-detail "  id=${el.id}+${el.type}+${el.latitude}+${el.longitude}>详情</button>
                                            <button class = "btn-cancel "  id=${el.id}>取消</button>
                                            <button class = "btn-share "  id=${el.id}>分享</button>
                                            <button class = "btn-photo "  id=${el.id}+${el.name}>相册</button>
                                            </div>
                                        </div>         
                                    </li>`
                            html+=panel;

            }); //console.log("1:   "+data);

            return html;
          },
          onBeforeRefresh: function onBeforeRefresh() {
            console.log("brefore refresh");
          },
          onBeforeLoad: function onBeforeLoad() {
            console.log("brefore load");
          },
          onRefresh: function onRefresh() {
            // 刷新以后执行
            startButton();
            console.log("refreshed");
          },
          onLoad: function onLoad() {
            // 刷新以后执行
            startButton();
            console.log("loaded");
          }
        });

        function startButton() {
          //详细按钮
          $(".btn-detail").on("click", function (e) {
            var id = $(this).attr('id');
            console.log(id);
            var list = id.trim().split("+"); //console.log(list);

            bui.load({
              url: "pages/activitydetail/activitydetail",
              param: {
                id: list[0],
                type: list[1],
                lat: list[2],
                lng: list[3]
              }
            });
          }, function (res, status) {
            console.log(status);
          }); //取消按钮

          $(".btn-cancel").on("click", function (e) {
            var id = $(this).attr('id');
            var name = $(this).attr('name');
            console.log(id);
            var idd = id.toString();
            var data_ = {
              "id": idd
            };
            data_ = JSON.stringify(data_);
            console.log(data_);
            var cancel = $(this);
            bui.confirm("确定要取消吗", function (e) {
              //this 是指点击的按钮
              var text2 = $(e.target).text();

              if (text2 == "确定") {
                // 执行删除整行操作
                bui.ajax({
                  url: config.apiurl + "api/v1.0/delmyact",
                  method: "post",
                  data: data_,
                  headers: {
                    'Content-Type': 'application/json'
                  }
                }).done(function (res) {
                  console.log(res);
                  bui.ajax({
                    url: config.apiurl + "api/v1.0/mychange",
                    data: {},
                    method: "post",
                    headers: {
                      'Content-Type': 'application/json'
                    }
                  }).done(function (res) {
                    $("#p3").text(res['acts']);
                  });
                  cancel.parents("li").fadeOut(300, function () {
                    cancel.remove();
                  });
                  bui.hint({
                    content: "<i class='icon-check'></i><br />取消成功",
                    position: "center",
                    effect: "fadeInDown"
                  });
                }).fail(function (res, status) {
                  console.log(status);
                  bui.hint("取消失败");
                });
              }
            });
          }, function (res, status) {
            console.log(status);
          }); //分享按钮

							
          $(".btn-share").on("click",function(t) {
              i = $(this).attr("id");
              var n = bui.actionsheet({
                appendTo: "#myjoinactivity",
                buttons: [{
                    name: "微信好友分享",
                    value: "session"
                },
                {
                    name: "微信好友圈分享",
                    value: "timeline"
                }],
                callback: function(t) {
                    switch ($(t.target).attr("value")) {
                    case "session":
                        var n = {
                            id: i
                        };
                        console.log(i);
                        n = JSON.stringify(n),
                        bui.ajax({
                            url: config.apiurl + "api/v1.0/actdetails",
                            data: n,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json"
                            }
                        }).then(function(t) {
                            var n = Number(t.peoplecount),
                            e = Number(t.peoplesurplus),
                            o = String(n - e) + "/" + String(n);
                            console.log(t.name, t.content, t.time, t.address, t.cost, o),
                            console.log("jin2");
                            shareHref1(i, t.name, t.content, t.time, t.address, t.cost, o, "session")
                        },
                        function(t, n) {
                          console.log("jin3");
                            console.log(n)
                        }),
                        this.hide();
                        break;
                    case "timeline":
                        n = {
                            id: i
                        };
                        n = JSON.stringify(n),
                        bui.ajax({
                            url: config.apiurl + "api/v1.0/actdetails",
                            data: n,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json"
                            }
                        }).then(function(t) {
                            var n = Number(t.peoplecount),
                            e = Number(t.peoplesurplus),
                            o = String(n - e) + "/" + String(n);
                            console.log(t.name, t.content, t.time, t.address, t.cost, o),
                            shareHref1(i, t.name, t.content, t.time, t.address, t.cost, o, "timeline")
                        },
                        function(t, n) {
                            console.log(n)
                        }),
                        this.hide();
                        break;
                    case "cancel":
                        this.hide()
                    }
                }
            });
              n.show()
          }), //相册按钮

          $(".btn-photo").on("click", function (e) {
            var id = $(this).attr('id');
            console.log(id);
            var totalimagelist; //用于删除图片传递参数

            var list = id.trim().split("+");
            $("#activity_name").text(list[1]);
            var idd = list[0].toString();
            var data_ = {
              "actid": idd
            };
            data_ = JSON.stringify(data_);
            console.log(data_);
            var $list_container = $("#panelfix"); //包含所有照片的list每次清空放置照片叠加

            var previous = "<div class=\"img-listsadd\" id=\"add\">\n                                        <img src=\"images/home/add_photo.png\"/>\n                                     </div>";
            var $photopart = $("#add");
            var uiUpload = bui.upload({
              showProgress: true // needNative: false

            });
            loadstart();

            function loadstart() {
              bui.ajax({
                url: config.apiurl + "api/v1.0/image_request",
                data: data_,
                method: "post",
                headers: {
                  'Content-Type': 'application/json'
                }
              }).done(function (res) {
                //console.log(res["photolist"]);
                var personimage;
                var image;
                personimage = res["photolist"];
                totalimagelist = res["photolist"];

                for (var i in personimage) {
                  image = "http://121.89.201.29:5000/static/activity_photos/" + personimage[i] + "?temp=" + Date.now(); //在src后面增加一个随机数避免图片无法更新

                  console.log(image);
                  $photopart.before(templatePhoto(image, personimage[i].slice(0, 40))); //console.log(personimage[i].slice(0,40));
                } //删除图像
                //console.log(totalimagelist);


                recycle();

                function recycle() {
                  $(".del_btn1").on("click", function () {
                    console.log(totalimagelist); // 加入复选框 

                    for (var i in totalimagelist) {
                      var checkBox = document.createElement("input");
                      checkBox.setAttribute("type", "checkbox");
                      checkBox.setAttribute("id", totalimagelist[i].slice(0, 40) + "checkbox");
                      checkBox.setAttribute("class", "delbox");
                      checkBox.setAttribute("name", "123");
                      var del = $("#" + totalimagelist[i].slice(0, 40));
                      del.append(checkBox); //checkBox.checked=true;
                    }

                    $("#delpanel").html("<button class=\"del_btn2\" id=\"del\">\u5220\u9664</button>");
                    $(".del_btn2").on("click", function () {
                      for (var i in totalimagelist) {
                        var delbox = $("#" + totalimagelist[i].slice(0, 40) + "checkbox");

                        if (delbox.is(':checked')) {
                          var deleteid = delbox.attr('id').slice(0, 40) + ".jpg";
                          console.log(deleteid);
                          var data_ = {
                            "photoname": deleteid
                          };
                          data_ = JSON.stringify(data_);
                          console.log(data_);
                          bui.ajax({
                            url: config.apiurl + "api/v1.0/image_delete",
                            method: "DELETE",
                            data: data_,
                            headers: {
                              'Content-Type': 'application/json'
                            }
                          }).then(function (res) {
                            console.log(res);
                            bui.hint({
                              content: "<i class='icon-check'></i><br />删除成功",
                              position: "center",
                              effect: "fadeInDown"
                            });
                          }, function (res, status) {
                            console.log(status);
                          }); // //动态删除照片

                          $("#" + totalimagelist[i].slice(0, 40)).remove();
                        }
                      }

                      var del = $(".img-lists");
                      del.find(".delbox").remove();
                      $("#delpanel").html("<button class=\"del_btn1\" id=\"delmanager\">\u7BA1\u7406</button>");
                      recycle();
                    });
                  });
                }
              }).fail(function (res, status) {
                console.log(status); // status = "timeout" || "error" || "abort", "parsererror"
              });
            } // 自定义居中弹出框




            var uiDialog = bui.dialog({
              id: "#dialogCenter",
              height: 400,
              fullscreen: true,
              style: {
                left: "5%",
                right: "5%",
                top: "10%",
                bottom: "10%"
              },
              // mask: false,
              callback: function callback(e) {
                console.log(e.target);
              },
              onClose: function onClose() {
                $("#delpanel").html("<button class=\"del_btn1\" id=\"delmanager\">\u7BA1\u7406</button>");
                $list_container.html(previous);
              }
            });
            uiDialog.open();
            $("#add").on("click", function () {
              uiUpload.add({
                "from": "",
                "needCompress": true,
                // 1.5.3新增压缩
                // "width": 300,
                "destinationType": "file",
                //  file | blob | data 
                "onSuccess": function onSuccess(val, data) {
                  console.log(data[0]['data']); // EXIF.getData(data[0]['data'], function() {
                  //     //alert(EXIF.pretty(this));
                  //     var aaa = EXIF.getAllTags(this); 
                  //     //alert(EXIF.getTag(this, 'Orientation')); 
                  //     var model = EXIF.getTag(this, "Model");
                  //     console.log(model);
                  //     //return;
                  // });

                  this.toBase64({
                    onSuccess: function onSuccess(url) {
                      var uiLoading = bui.loading();
                      uiLoading.show();
                      console.log(url); //var file = dataURLtoFile(url, Date.now()+'.jpg');
                      // EXIF.getData(file, function() {
                      //      //alert(EXIF.pretty(this));
                      //      var aaa = EXIF.getAllTags(this); 
                      //      //alert(EXIF.getTag(this, 'Orientation')); 
                      //      var model = EXIF.getTag(this, "Model");
                      //      console.log(model);
                      //      //return;
                      //  });
                      // var form = new FormData();
                      // form.append("actid",idd);
                      // form.append("image",file,"liger");

                      var data2 = {
                        actid: idd,
                        base64: url
                      };
                      data2 = JSON.stringify(data2);
                      console.log(data2);
                      bui.ajax({
                        url: config.apiurl + "api/v1.0/image_upload2",
                        data: data2,
                        method: "post",
                        headers: {
                          'Content-Type': 'application/json'
                        }
                      }).then(function (res) {
                        //$photopart.before(templatePhoto(url,data['avatar_url'].slice(0,40)));
                        $('#delpanel').find('.del_btn1').remove();
                        $('#delpanel').html("<button class=\"del_btn1\" id=\"delmanager\">\u7BA1\u7406</button>");
                        $list_container.find('.img-lists').remove(); //$list_container.find('.del_btn2').remove();

                        bui.hint({
                          content: "<i class='icon-check'></i><br />上传成功",
                          position: "center",
                          effect: "fadeInDown"
                        });
                        loadstart();
                        uiLoading.hide(); //$('#'+list[0].toString()+'+'+list[1].toString()).click();

                        console.log(res);
                      }, function (res, status) {
                        alert("修改失败，请检查网络！");
                      }); // $.ajax({
                      //     url: config.apiurl + "api/v1.0/image_upload2",
                      //     type: 'POST',
                      //     cache: false,
                      //     //上传文件不需要缓存
                      //     data: data2,
                      //     processData: false,
                      //     // 告诉jQuery不要去处理发送的数据
                      //     contentType: false,
                      //     // 告诉jQuery不要去设置Content-Type请求头
                      //     success: function success(data) {
                      //       //$photopart.before(templatePhoto(url,data['avatar_url'].slice(0,40)));
                      //       $('#delpanel').find('.del_btn1').remove();
                      //       $('#delpanel').html("<button class=\"del_btn1\" id=\"delmanager\">\u7BA1\u7406</button>");
                      //       $list_container.find('.img-lists').remove(); //$list_container.find('.del_btn2').remove();
                      //       bui.hint({
                      //         content: "<i class='icon-check'></i><br />上传成功",
                      //         position: "center",
                      //         effect: "fadeInDown"
                      //       });
                      //       loadstart();
                      //       uiLoading.hide();
                      //       console.log(data); //$('#'+list[0].toString()+'+'+list[1].toString()).click();
                      //     }
                      //   }); //uiDialog.close();
                    },
                    onFail: function onFail(url) {
                      bui.alert(url); // $uploadBtn.before(templatePhoto(url))
                    }
                  });
                }
              });
            });
          }, function (res, status) {
            console.log(status);
          }); // //底部分享页面弹出框
          // var uiActionsheet = bui.actionsheet({
          //     trigger: ".btn-share",
          //     buttons: [{ name: "分享到微信", value: "weixin" }],
          //     callback: function(e) {
          //         var ui = this;
          //         var val = $(e.target).attr("value");
          //         switch (val) {
          //             case "cancel":
          //                 ui.hide();
          //                 break;
          //             case "weixin":
          //                 break;
          //         }
          //     }
          // })
        }

        function todo(e) {
          var val = $(e.target).attr("value");
          console.log(val);

          if (val == "cancel") {
            this.hide();
          }
        }

        function dataURLtoFile(dataurl, filename) {
          var arr = dataurl.split(','),
              mime = arr[0].match(/:(.*?);/)[1],
              bstr = atob(arr[1]),
              n = bstr.length,
              u8arr = new Uint8Array(n);

          while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
          }

          return new File([u8arr], filename, {
            type: mime
          });
        }

        function templatePhoto(url, id) {
          return "<div class=\"img-lists\" id=".concat(id, ">\n                                <img src=\"").concat(url, "\" onClick='checkphoto(this.src);'/>\n                            </div>");
        } // $("header").click(function() {
        //     // 清空
        //     uiList.empty();
        //     // 修改数据
        //     uiList.init({
        //         page: 1,
        //         "data": {
        //             test: "111"
        //         }
        //     })
        // })


        return uiList;
      }
    };
    this.pageview.init();
    return this.pageview;
  }
});
},{}]},{},[1]);
